﻿using AutoMapper;
using B.S.Orders.Domain;
using B.S.Orders.ErrorCord;
using B.S.Orders.Read.Api.Application.Commands.ProjectModelCommand;
using MediatR;
using SqlSugar;

namespace B.S.Orders.Read.Api.Application.CommandsHander.ProjectModelCommandHander
{
    public class ShowProjectModelCommandHander : IRequestHandler<ShowProjectModelCommand, APIResult<List<ProjectModel>>>
    {
        private readonly IMapper mapper;
        private readonly ISqlSugarClient db;

        public ShowProjectModelCommandHander(IMapper mapper, ISqlSugarClient db)
        {
            this.mapper = mapper;
            this.db = db;
        }

        public async Task<APIResult<List<ProjectModel>>> Handle(ShowProjectModelCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ProjectModel>> result = new APIResult<List<ProjectModel>>();

            var item = await db.Queryable<ProjectModel>().Where(x => x.Del == false).ToListAsync();

            result.Code = APIEnum.success;
            result.Msg = "查询产品信息成功";
            result.Data = item;

            return result;
        }
    }
}
